$(document).ready(function() {
    $('#data-table').dataTable({
        "sAjaxSource": url + "/control/productlist.html",
        "bServerSide": true,
        "bJQueryUI": true,
        "bStateSave":true,
        "oLanguage": {
            "sSearch": "搜索：",
            "sLengthMenu": "每页显示 _MENU_ 条记录",
            "sZeroRecords": "抱歉， 没有找到",
            "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
            "sInfoEmpty": "没有数据",
            "sInfoFiltered": "(从 _TOTAL_ 条数据中检索)",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            },
            "sZeroRecords": "没有检索到数据",
        },
        "aaSorting": [[0, 'desc']],
        "aoColumns": [
            {"mDataProp": "id",
                "sWidth": "1%",
                "sClass":"hidden",
                "bSortable": false,
                "fnRender": function(data) {
                    return '<input type="checkbox" id="check" value="' + data.aData.id + '" /><input type="hidden" id="typeid"  value="' + data.aData.typeid + '" />';
                }
            },
            {"mDataProp": "title",
                "fnRender": function(obj) {
                    var sReturn = obj.aData.title;
                    return sReturn;
                }
            },
            {"mDataProp": "name",
                "sWidth": 100,
            },
            {"mData": null,
                "bSortable": false,
                "sWidth": 40,
                "sClass":"text-center",
                "fnRender": function(obj) {
                    var sReturn = '<span style="width:100px" >'+obj.aData.price+'</span>';
                    return sReturn;
                }
            }
        ],
        "fnCreatedRow":function(nRow, aData, iDataIndex){
           $(nRow).attr("data-toggle","tooltip");
           $(nRow).attr("data-original-title","<img src='"+url+aData['litpic']+"'  />");
        },
        "fnServerData": function(sSource, aoData, fnCallback) {
            $.ajax({
                "dataType": 'json',
                "type": "post",
                "url": sSource,
                "data": aoData,
                "success": function(resp)
                {
                    fnCallback(resp);
                    $("#data-table").children("tbody").children("tr").tooltip({"html":true});
                    $("#data-table").children("tbody").children("tr").click(function(){
                        var typeid=$(this).children("td:first").children("#typeid").val();
                        var str=url+"/control/productinfo/"+typeid+"/"+$(this).children("td:first").children("input:first").attr("value")+".html";
                        window.open(str);
                    });
                }
            });
        }
    });

    $("span.icon input:checkbox, th input:checkbox").click(function() {
        var checkedStatus = this.checked;
        var checkbox = $(this).parents('.widget-box').find('tr td:first-child input:checkbox');
        checkbox.each(function() {
            this.checked = checkedStatus;
            if (checkedStatus == this.checked) {
                $(this).closest('.checker > span').removeClass('checked');
            }
            if (this.checked) {
                $(this).closest('.checker > span').addClass('checked');
            }
        });
    });
    
});
